﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CRMWebServices.Models;

namespace CRMWebServices
{
    /// <summary>
    /// Сводное описание для AuthWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Чтобы разрешить вызывать веб-службу из скрипта с помощью ASP.NET AJAX, раскомментируйте следующую строку. 
    [System.Web.Script.Services.ScriptService]
    public class AuthWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public object Auth(string userName, string password, bool auto)
        {
            if (!this.Authorize(userName, password, auto))
            {
                AuthModel authModel = new AuthModel();
                authModel.Name = "modelAuth";
                authModel.Title = "Please enter your user name and password, sir.";
                authModel.User = userName;
                authModel.Password = password;
                authModel.Auto = auto;
                authModel.Error = "Your name or password is incorrect!";

                return authModel;
            }

            ObjectListModel olModel = new ObjectListModel();
            olModel.Name = "modelList";
            olModel.Title = "Server object list";
            olModel.Items = new ItemModel[10];
            for (int i = 0; i < 10; i++)
            {
                olModel.Items[i] = new ItemModel(string.Format("#{0}: {1}", i, DateTime.Now.ToString()));
            }
            olModel.ShowRenderTimes = true;

            return olModel;
        }

        public bool Authorize(string userName, string password, bool auto)
        {
            if (userName == "Shakh Denis" && password == "123")
            {
                return true;
            }

            return false;
        }
    }
}
